package com.abc.fast.server.user.domain.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@AllArgsConstructor
@Getter
public enum RoleEnum {

    USER(1L, "用户"),
    ADMIN(2L, "管理员"),
    SUPER(3L, "超级管理员");

    private Long roleId;
    private String desc;

    private static Map<Long, RoleEnum> cache;

    static {
        cache = Arrays.stream(RoleEnum.values()).collect(Collectors.toMap(RoleEnum::getRoleId, Function.identity()));
    }

    public static RoleEnum of(Integer type) {
        return cache.get(type);
    }
}
